package com.cmii.sjw.department.control.Interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

// @Component
public class RequestInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // HttpSession session = request.getSession(false);
        // // 检查session是否存在，并且session中是否有对应的用户信息。如果都满足，则返回
        // if (session != null && session.getAttribute(UserConstant.USER_LOGIN_STATE) != null) {
        //     return true;
        // }
        // response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        // response.setContentType("application/json");
        // response.setCharacterEncoding("UTF-8");
        // String jsonString = JSON.toJSONString(Result.error(403, "请求中未携带有效信息，请检查"));
        // response.getWriter().write(jsonString);
        // return false;
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
